/*
** ftrace.h for ftrace.g in /home/vermel/local/epitech/tek2/c/ftrace/pullup-project
** 
** Made by nathan vermelle
** Login   <vermel_n@epitech.net>
** 
** Started on  Fri Jun 29 14:08:29 2012 nathan vermelle
** Last update Sun Jul  1 17:42:34 2012 nathan vermelle
*/

/*INCLUDES SYSTEMES*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <stdio.h>
#include <sys/reg.h>
#include <sys/user.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

/* MACROS QUI DECHIRE TOUT */
#define	SYSCALL(x) ((x & 0xffff) == 0x80cd)
#define E8CALL(x) ((x & 0xff) == 0xe8)
#define A9CALL(x) ((x & 0x9a) == 0x9a)
#define FFCALL(x) ((x & 0xff) == 0xff)
#define RETURNVAL(x) (((x & 0xff) == 0xcb) || ((x & 0xff) == 0xc3))

typedef enum{
  CALL,
  SYSCALL,
  LIB
}		TYPE;

typedef struct		s_token
{
  int			number;
  char			*name;
  struct s_token	*next;
}			t_token;

typedef struct	s_tree
{
  char		*name;
  char		*lib;
  TYPE		type;
  struct s_tree	**sons;
}		t_tree;

/* PROTOTYPES DE LA MORT OH YEAH ! */
/*ANALYZE.C*/
char		*get_syscall(unsigned int pos);
int		checkSysCalls(struct user_regs_struct regs, unsigned long Lrip);
int		analyzeProc(pid_t pid, struct user_regs_struct regs);

/*LAUNCHER.C*/
void	launch_ftrace(char *command);
void	launch_ftracePid(pid_t pid);
void	merror(char *message);

/*runProc.c*/
void		runChildProc(pid_t pid, char *cmd);
void		runChildProcPid(pid_t pid);
void		runFatherProc(pid_t pid);

/**SIGNAL.C*/
void	handler(int sig);
void	catchSignal(unsigned int pid);

/* file_generator_utils.c */
int		get_token(t_token *, char *);
char		*make_string(int, int, int*);
void		write_database(t_token *, int);

/* file_generator.c */
void		add_in_token(char *, t_token **);
int		is_in(char *, t_token *);
void		pars_tree(t_tree *, t_tree *, t_token *, int);
void		make_file(t_tree *);
